<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
  <head>
  <title>Safety Vault</title>
  <link rel="stylesheet" href="css/style.css" type="text/css">
  <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
  <!--[if gte IE 5.5]>
  <![if lt IE 7]>
  <style type="text/css">
  div.sv-fixed {
    position: absolute;
    right: auto;
    bottom: auto;
    left: expression( ( ignoreMe = document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ) + 'px' );
    top: expression( ( ignoreMe2 = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ) + 'px' );
  }
  </style>
  <![endif]>
  <![endif]-->
  <script src="/js/g-aes.js" type="text/javascript">
  </script>
  <script type="text/javascript">
    function encrypt() {
      var key = document.getElementById('aes-key');
      var key_v = key.value;
      var passwd = document.getElementById('password');
      var passwd_v = passwd.value;
      if (key_v) {
        var enc_passwd = GibberishAES.enc(passwd_v, key_v);
        passwd.value = enc_passwd;
        passwd.type = 'text';
        {% if clear_key_after_each_use %}
        key.value = '';
        {% endif %}
        return true;
      } else {
        alert('Key empty, please enter one.');
        key.focus();
        return false;
      }
    }
    function decrypt(idx) {
      var key = document.getElementById('aes-key');
      var key_v = key.value;
      var enc_passwd = document.getElementById('encpass' + idx);
      var enc_passwd_tc = enc_passwd.textContent;
      if (key_v) {
        try{
          var passwd = GibberishAES.dec(enc_passwd_tc, key_v);
        } catch(ex) {
          alert(ex);
          key.select(0,key.value.length);
          key.focus();
          return;
        }
        enc_passwd.textContent = passwd;
        {% if clear_key_after_each_use %}
        key.value = '';
        {% endif %}
        window.setTimeout(function() {
          enc_passwd.textContent = enc_passwd_tc;
          }, 1000);
      } else {
        alert('Key empty, please enter one.');
        key.focus();
      }
    }
  </script>
  </head>

  <body>
    {% include "title-logo.tpl" %}
      <tr class="sv-tr-logout"><td>
        <a href="http://code.google.com/p/safety-vault/" target="_blank" onclick="this.blur()">Project Page</a> | 
        <a href="http://code.google.com/p/safety-vault/issues/entry" target="_blank" onclick="this.blur()">Report a bug</a> | 
        <a href="/help" target="_blank" onclick="this.blur()">Help</a> |
        <a href="{{ logout_url }}" onclick="this.blur();">Logout</a>
      </td></tr>
    </table>
    <table width="50%" class="sv-table-passwd" align="center">
      {% for passwd in passwds %}
      <tr class="{% cycle sv-tr-passwd-alt1,sv-tr-passwd-alt2 %}">
        <td>
        <table>
        <tr><td>Username:</td><td>{{ passwd.username }} (<a href='/del?key={{ passwd.key }}' onclick="this.blur();return confirm('Are you sure you want to delete?');">X</a>)</td></tr>
        <tr><td>Password:</td><td><span id="encpass{{ forloop.counter }}">{{ passwd.password }}</span></td></tr>
        <tr><td>Link:</td><td><a href="{{ passwd.link }}" target="_blank">{{ passwd.link }}</a></td></tr>
        <tr><td>Info:</td><td>{{ passwd.info }}</td></tr>
        <tr colspan="2"><td><button onclick="this.blur();decrypt({{ forloop.counter }});">Decrypt</button></td></tr>
        </table>
        </td>
      </tr>
      {% endfor %}
      <tr class="sv-tr-passwd-new">
        <td>
        <form action="/add" method="post" onsubmit="return encrypt();">
        <table>
        <tr><td>Username:</td><td><input type="text" name="username"></td</tr>
        <tr><td>Password:</td><td><input type="password" name="password" id="password"></td></tr>
        <tr><td>Link:</td><td><input type="text" name="link"></td></tr>
        <tr><td>Info:</td><td><input type="text" name="info"></td></tr>
        <tr colspan="2"><td><input type="submit" value="Add" onclick="this.blur();"></td></tr>
        </form>
        </td>
      </tr>
    </table>
    <div class="sv-div-aes sv-fixed">
      AES-Key: <input type="password" id="aes-key"><img class="sv-img-va sv-img-del" src="/images/del.png" onclick="document.getElementById('aes-key').value=''">
    </div>
    {% include "ga.tpl" %}
  </body>
</html>
